<template>
	<view class="calendar">
		<image src="../../static/img/sign.png" class="bg"></image>
		<view class="day">
			<view class="jifen">
				<view class="fs-23 bold">{{personInfo.score}}</view>
				<view class="fs-13">当前积分</view>
			</view>
			<view class="sign">
				<ss-calendar :checks="checks" />
				<button type="default" @click="onSignInToday" v-if="!disabled">立即签到</button>
				<button type="default" v-else class="is-sign">已经签到</button>
			</view>
		</view>
		<view class="recomend" v-if="recommendList.length">
			<view class="title">
				<!-- <image src="../../static/img/cucumber.png" style="width: 66rpx;height:32rpx;" mode="widthFix"></image> -->
				<text class="name">精选推荐</text>
			</view>
			<view class="body">
				<my-recomend v-for="(item, index) in recommendList" :key="index" :ware="item" :config="config"
					@showCart="openCart(item)" class="myc_recomend"></my-recomend>
			</view>
		</view>

	</view>
</template>

<script>
	import ssCalendar from '@/components/ss-calendar/ss-calendar.vue'
	export default {
		data() {
			return {
				checks: [],
				recommendList: [],
				personInfo:{}
			}
		},
		components: {
			ssCalendar
		},
		computed: {
			disabled() {
				let {
					year,
					month,
					day
				} = this.getCurrentDate()

                if(month<10) month='0'+month;
				if(day<10) day='0'+day;
				
				
				return this.checks.includes(year+'-'+month+'-'+day);
			}
		},
		onShow() {
			this.moreSign();
			this.indexMainRecommend();
			this.getScore()
		},
		methods: {
			getScore() {
				let params = {
					token: uni.getStorageSync('userToken')
				}
				this.$get(this.$api.userInfo, params, (res) => {
					let {
						data
					} = res;
					
					if (data.code == 1) {
						this.personInfo = data.data;
					}
				})
			},
			moreSign() {
				const {
					year,
					month,
					day
				} = this.getCurrentDate()
				let params = {
					type: 2,
					moth:month
				}
				this.$get(this.$api.iLists,params, res => {
					let data = res.data;
					
					
					if (data.code == 1) {
                      this.checks=data.data;
					  console.log(this.checks);
					}
				});
			},
			indexMainRecommend() {
				let {
					page
				} = this;
				this.$get(this.$api.mainRecommend, {
					page
				}, res => {
					let data = res.data;
					if (data.code == 1) {
						this.recommendList = this.recommendList.concat(data.data);
					}
				});
			},
			onSignInToday() {
				const {
					year,
					month,
					day
				} = this.getCurrentDate()
				this.$get(this.$api.iSign, {}, (res) => {
					if (res.data.code == 1) {
						this.$Toast('签到成功');
							this.checks.push(`${year}-${month}-${day}`);
							this.getScore()
					}
				})
			

			},
			getCurrentDate() {
				const date = new Date()
				const year = date.getFullYear()
				const month = date.getMonth() + 1
				const day = date.getDate()

				return {
					year,
					month,
					day
				}
			},

		}
	}
</script>
<style lang="scss" scoped>
	.bg {
		position: absolute;
		width: 100%;
		height: 300rpx;
		border-radius: 0 0 40rpx 40rpx;
	}

	.sign {
		margin: 0 30rpx;
		border-radius: 10rpx;
		background: white;
		padding-bottom: 20rpx;

		button {
			background: #FF7133;
			height: 80rpx;
			line-height: 80rpx;
			border-radius: 40rpx;
			margin: 20rpx;
			color: white;
			font-size: 30rpx;
		}

		.is-sign {
			background: #b1b1b1;
		}
	}

	.day {
		position: relative;
		z-index: 9;

		.jifen {
			color: white;
			text-align: center;
			height: 200rpx;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
		}
	}

	.body {
		display: flex;
		flex-wrap: wrap;
		margin-bottom: 30rpx;
		justify-content: space-between;
	}
</style>
